/**
 * Created with JetBrains WebStorm.
 * User: hoangnm
 * Date: 4/24/13
 * Time: 10:53 PM
 * To change this template use File | Settings | File Templates.
 */
function scrollBanner() {
    //Get the scoll position of the page
    scrollPos = $(this).scrollTop();
    //Scroll the background of the banner
    $('#header').css({
        'background-position': 'center ' + (-scrollPos / 8) + "px"
    });
  }
function isMobile(){
    return (
        (navigator.userAgent.match(/Android/i)) ||
		(navigator.userAgent.match(/webOS/i)) ||
		(navigator.userAgent.match(/iPhone/i)) ||
		(navigator.userAgent.match(/iPod/i)) ||
		(navigator.userAgent.match(/iPad/i)) ||
		(navigator.userAgent.match(/BlackBerry/))
    );
}

$(function(){
    var sys_about_testimonial = $("#sys_about_testimonial"),
        sys_indicators = $("#sys_indicators"),
        sys_lst_people_name = $("#sys_lst_people_name"),
        sys_present_lst = $("#sys_present_lst");
    if(!isMobile()) {
        $(window).scroll(function() {
           scrollBanner();
        });
    }
    var options = {
        pagination: true,
        animateStartingFrameIn: true,
        autoPlay: true,
        autoPlayDelay: 6500,
        preloader: true,
        preloadTheseFrames: [1],
        preloadTheseImages: []
    };
    var mySequence = $("#sequence").sequence(options).data("sequence");
    getTwitters('sys_lst_tweets', {
        id: 'megadrupal',
        count: 2,
        template: '<div class="tweet-item"><p class="rs tweet-mind">%text%</p><p class="rs timestamp">posted %time%</p><i class="icon iTwitter"></i></div>'
    });

    if(sys_about_testimonial.length>0) {
        sys_indicators.on("click",".dot-gray",function(){
            var getIdx=$(this).index();
            sys_indicators.children().removeClass("active").end().children(":eq(" + getIdx + ")").addClass("active");
            sys_present_lst.children().removeClass("active").hide();
            sys_present_lst.children(":eq(" + getIdx + ")").fadeIn(function() {
                $(this).addClass("active");
            });
            sys_lst_people_name.children().removeClass("active").hide();
            sys_lst_people_name.children(":eq(" + getIdx + ")").fadeIn(function() {
                $(this).addClass("active");
            });
        });
    }
    function autoTestimonial() {
        var getIdx = sys_present_lst.children(".active").index(),
            lengthTestimonial = sys_present_lst.children().length;
        getIdx++;
        if(getIdx==lengthTestimonial)
            getIdx = 0;
        sys_indicators.children().removeClass("active").end().children(":eq(" + getIdx + ")").addClass("active");
        sys_present_lst.children().removeClass("active").hide();
        sys_present_lst.children(":eq(" + getIdx + ")").fadeIn(function() {
            $(this).addClass("active");
        });
        sys_lst_people_name.children().removeClass("active").hide();
        sys_lst_people_name.children(":eq(" + getIdx + ")").fadeIn(function() {
            $(this).addClass("active");
        });
    }
    setInterval(function(){
        autoTestimonial();
    },6000);

    // Sidr menu
    $('#btn-toogle-menu').sidr({
        side:"right",
        name:"alternate-menu",
        source:"#right-menu"
    });
});